package cn.edu.live.dao;

import cn.edu.live.model.Anchor;

public class AnchorDao {

	/**
	 * 顺序使用参数id，username，usermail，优先使用第一个且仅使用一个有效参数来查询。(此方法不区分type)
	 * 
	 * 此处不允许用户的username，uesrmail有重复
	 * 
	 * 无效参数：id=0，username=null，usermail=null
	 * 
	 * @param id
	 * @param username
	 * @param usermail
	 * @return
	 */
	public Anchor findByOneParam(int id, String username, String usermail) {
		String sql = null;

		if (id != 0) {
			sql = "select * from anchor where id = ?";
			return Anchor.dao.findFirst(sql, id);
		}
		if (username != null) {
			sql = "select * from anchor where username = ?";
			return Anchor.dao.findFirst(sql, username);
		}
		if (usermail != null) {
			sql = "select * from anchor where usermail = ?";
			return Anchor.dao.findFirst(sql, usermail);
		}
		return null;
	}

	public Anchor findByInfoid(int infoid) {
		String sql = "select * from anchor where infoid = ?";
		return Anchor.dao.findFirst(sql);
	}

}
